<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增转发公文')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-manager-addSendDoc" th:object="${docManager}">
        <input name="id" th:field="*{id}" th:value="*{id}" type="hidden">
        <input name="deptId" type="hidden" id="treeId"/>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required" >公文号：</label>
            <div class="col-sm-8">
                <input name="docOrder" th:field="*{docOrder}" class="form-control" type="text" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">公文标题：</label>
            <div class="col-sm-8">
                <input name="docTitle" th:field="*{docTitle}" class="form-control" type="text" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">公文批示：</label>
            <div class="col-sm-8">
                <input name="userContent"  class="form-control" type="text" >
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">转发日期：</label>
            <div class="col-sm-8">
                <div class="input-group date">
                    <input name="docDate" th:value="${#dates.format(docManager.docDate,'yyyy-MM-dd')}" class="form-control" placeholder="yyyy-MM-dd" type="text" required>
                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                </div>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label is-required">部门选择：</label>
            <div class="col-sm-8">
                <div class="input-group">
                    <input class="form-control" type="text" name="deptName"  id="treeName" onclick="selectDeptTree()" th:field="*{dept.deptName}">
                    <span class="input-group-addon"><i class="fa fa-search"></i></span>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-offset-5 col-sm-10">
                <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>保 存</button>&nbsp;
                <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭 </button>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: datetimepicker-js" />
<script th:inline="javascript">
    var prefix = ctx + "docManager/manager";
    $("#form-manager-addSendDoc").validate({
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            var deptId = $.common.isEmpty($("#treeId").val()) ? "100" : $("#treeId").val();
            var docId =$('input[name="id"]').val();
            var userContent = $('input[name="userContent"]').val();
            var receiveDate = $('input[name="docDate"]').val();
            var status = 1;
            var data = {"docId":docId,"deptId":deptId,"userContent":userContent,"receiveDate":receiveDate,"status":status};
            console.log(data)
            $.operate.save(prefix + "/addSendDoc",data);
        }
    }
    function selectDeptTree() {
        var deptId = $.common.isEmpty($("#treeId").val()) ? "100" : $("#treeId").val();
        var url = ctx + "docManager/manager/selectDeptTree/" + deptId;
        var options = {
            title: '选择部门',
            width: "380",
            url: url,
            callBack: doSubmit
        };
        $.modal.openOptions(options);
    }
    function doSubmit(index, layero){
        var body = $.modal.getChildFrame(index);
        $("#treeId").val(body.find('#treeId').val());
        $("#treeName").val(body.find('#treeName').val());
        $.modal.close(index);
    }

    $("input[name='docDate']").datetimepicker({
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true
    });
</script>
</body>
</html>